import {request} from "@/utils/request";
import type {UploadAnimal, UploadDataImage, UploadImageDTO} from "@/types/upload";
import type {PageResult} from "@/types/PageResult";

/**
 * 上传动物信息
 * @param data 动物信息
 */
export const uploadAnimalsApi = (data: UploadAnimal) => {
    data.imgURL = data.imgList[0].url
    return request<string>({
        url: '/uploadAnimals',
        method: 'POST',
        data
    })
}

export const uploadAnimalImagesApi = (data: UploadDataImage) => {
    return request<string>({
        url: '/upload/animal/images',
        method: 'POST',
        data
    })
}

/**
 * 上传管理页面用户获取上传图片信息
 * @param page
 * @param pageSize
 * @param type 审核状态
 */
export const getUserUploadImagesApi = (page: number, pageSize: number, type?: 0 | 1 | 2 | 3) => {
    return request<PageResult<UploadImageDTO[]>>({
        url: '/user/upload/center/img?page=' + page + '&pageSize=' + pageSize + (type !== undefined ? '&type=' + type : ''),
        method: 'GET',
    })
}

/**
 * 用户主动取消上传图片
 * @param id
 */
export const handleCancelImageApi = (id: number) => {
    return request<string>({
        url: '/user/upload/center/img/cancel?id=' + id,
        method: 'POST',
    })
}

/**
 *  用户主动删除上传图片
 * @param data
 */
export const handleDelImageApi = (data: UploadImageDTO) => {
    return request<string>({
        url: '/user/upload/center/img/delete',
        method: 'POST',
        data
    })
}

/**
 * 用户删除上传但未提交的图片
 * @param path
 */
export const delUserImageApi = (path: string) => {
    return request<void>({
        url: '/upload/image/delete?path=' + path,
        method: 'POST',
    })
}